import {$get, $post} from '../utils/request';
import {$msg_s, $msg_e} from '../utils/msg';

//获取角色列表
export const getRoleList = async () => {
  let data = await $get('Role/List');

  /* data = [
    {
      roleId: 1,
      roleName: '系统管理员',
    },
    {
      roleId: 2,
      roleName: '普通管理员',
    },
  ]; */

  return data;
}

//删除角色
export const delRole = (params) => {
  let data = $post('Role/Delete', params);

  data = {
    success: true,
    message: '删除角色成功',
  }

  const {success, message} = data;

  if(success){
    //成功
    $msg_s(message);
  }else{
    //失败
    $msg_e(message);
  }

  return success;
}

//添加、编辑角色
export const addEditRole = async (params, isAdd) => {
  if(!params.roleName){
    //未填写角色名称
    $msg_e('请输入角色名称');
    return false;
  }

  let data = {}

  if(isAdd){
    //添加
    data = await $post('Role/Add', params);

    /* data = {
      success: true,
      message: '添加角色成功',
    } */
  }else{
    //编辑
    data = $post('Role/Edit', params);

    data = {
      success: true,
      message: '编辑角色成功',
    }
  }

  const {success, message} = data;

  if(success){
    //成功
    $msg_s(message);
  }else{
    //失败
    $msg_e(message);
  }

  return success;
}